<template>
	<view class="container" v-if="formdata.obj">
		<page-meta :page-style="'overflow:'+(metaShow?'hidden':'visible')"></page-meta>
		<uni-forms ref="baseForm" label-position='top' label-width='100'>
			<uni-forms-item :label="item.edit == 0?item.cn_name+'：'+nullFun(formdata.obj[item.en_name]):item.cn_name"
				v-for="(item,index) in formdata.zdlist" :key="index" v-show="!hidezdlist.includes(item.en_name)"
				:required='item.bitian==1'>
				<view class="" v-if="item.edit == 0">
				</view>
			</uni-forms-item>
		</uni-forms>
		<upload-img :imgs="formdata.imgs" :obj="formdata.obj" :imgUrl="formdata.img_url"></upload-img>
		<view class="button-container">
			<view class="bottom-button" v-for="(btn, index) in formdata.anlist" :key="index"
				@click="toUrl_pinglun(btn)">
				<image class="button-icon" :src="`../../../static/img/`+btn.tubiao"></image>
				<text class="button-text">{{ btn.biaoti }}</text>
			</view>
		</view>
	</view>
</template>
<script>
	import Base64 from '@/utils/base64.js';
	import hzstools from '@/utils/hzstools.js';
	import http from '@/utils/request.js';
	import md5 from 'js-md5';
	import UploadImg from '@/components/uploadimg/uploadimg.vue'
	export default {
		components: {
			UploadImg
		},
		data() {
			return {
				faid: 0,
				id: 0,
				pingtaibh: '',
				formdata: {},
				xzlist: [],
				cxlx: 0,
				xzname: '',
				jkgongshi: [],
				kongobj: [],
				dx: 0,
				selectedValues: [],
				imageList: [], // 图片临时路径列表
				liuchengbh: '',
				ctype: 'add',
				lsobj: {},
				key: '',
				metaShow: false,
				objs: {},
				index: null,
				copy: 0,
				gzqx: 0,
				gzxb: 0,
				gzxbs: 0,
				Zhlist: {},
				Zhmoban: {},
				zib_faid: 0,
				jk_type: '',
				hidezdlist: [],
				location: null
			}
		},
		onLoad(options) {
			const app = getApp()
			console.log(app.globalData)
			this.faid = Number(options.faid)
			this.id = options.id
			this.cxlx = Number(options.cxlx)
			this.ctype = options.ctype
			this.jk_type = options.jk_type
			console.log(options);
			this.getShuju()
			uni.setNavigationBarColor({
				backgroundColor: uni.getStorageSync('userinfo').head_color, // 背景色
				frontColor: '#ffffff' // 文字颜色（仅支持 black/white）
			})
			// uni.getLocation({
			//   type: 'WGS84',
			//   success: (res) => {
			// 			console.log(res);
			//     this.location = `${res.latitude},${res.longitude}`;
			//   },
			//   fail: (err) => {
			// 			console.log(err);
			//     uni.showModal({
			//       title: '提示',
			//       content: '获取位置失败，请检查权限',
			//       showCancel: false
			//     });
			//   }
			// });
		},
		methods: {
			getShuju() {
				var that = this;
				var bs64_cs = {
					dtype: this.ctype,
					key: '',
					cxlx: this.cxlx,
					id:this.id,
					img_is_zj: 0,
					openid: uni.getSystemInfoSync().deviceId
				};
				var cs = {
					ctype: '',
					bs64_cs: '',
					bs64_obj: '',
					bs64_list: '',
					ids: '',
					faid: this.faid
				};
				console.log(bs64_cs);
				cs.ctype = this.jk_type; //save
				cs.bs64_cs = Base64.encode(JSON.stringify(bs64_cs));
				http.request({
						method: 'POST',
						data: {
							canshu: cs
						}
					})
					.then((cs) => {
						this.formdata = cs
						uni.setNavigationBarTitle({
							title: cs.ckbiaoti
						})
					})
			},
			
			toUrl_pinglun(item) {
				var that = this;
				const css = JSON.parse(JSON.stringify(item))
				if (css.ctype == "fanhui") {
					uni.navigateBack()
				} else if (css.ctype == "shouye") {
					uni.switchTab({
						url: '/pages/index/index'
					})
				} else if (css.ctype == "save") {
					that.saveShuju()
				} else if (css.ctype == "save_houtai") {
					that.save_Ht(css)
				} else if (css.ctype == "tijiao") {
					that.liucheng_tijiao()
				} else if (css.ctype == "shuaxin") {
					uni.showToast({
						title: '刷新成功',
						icon: 'none'
					})
					that.getShuju()
				}

			},
			save_Ht(csitem) {
				var that = this;
				var bs64_cs = {
					dtype: that.ctype,
					id: that.id,
					openid: uni.getSystemInfoSync().deviceId,
					jingweidu:this.location
				};
				var cs = {
					ctype: '',
					bs64_cs: '',
					bs64_obj: '',
					bs64_list: '',
					ids: '',
					faid: that.faid
				};
				cs.ctype = csitem.jk_type;
				cs.bs64_cs = Base64.encode(JSON.stringify(bs64_cs));
				cs.bs64_obj = Base64.encode(JSON.stringify(that.formdata.obj));
				http.request({
						method: 'POST',
						data: {
							canshu: cs
						}
					})
					.then((cs) => {
						if (cs.leixing == 'ok') {
							uni.showToast({
								title: '保存成功',
								success: () => {
									if (csitem.wc_fanhui > 0) {
										setTimeout(() => {
											that.fanhui()
										}, 1000)
									} else {
										setTimeout(() => {
											this.getShuju()
										}, 1000)
									}
								}
							})
						} else {
							uni.showToast({
								title: cs.msg,
								icon: "error"
							})
						}
					})
			},
			nullFun(item) {
				const items = item === null ? 0 : item
				return items
			},
			fanhui(){
				let pages = getCurrentPages();
				let prevPage = pages[pages.length - 2];
				var cs = hzstools.objUrl_ZhuanMa(this.formdata.obj);
				prevPage.refreshShuju();
				uni.navigateBack()
			}
			
			
			
		}
	}
</script>

<style lang="scss" scoped>


	.container {
		padding: 20px;
		position: relative;
		padding-bottom: 120rpx;
	}

	
	.up-img {
		margin-top: 30rpx;
		display: flex;
		justify-content: space-between;
		align-items: center;

		.kuai {
			width: 50rpx;
			height: 100%;
		}

		button {
			width: 100%;
		}
	}

	/* 固定在底部的按钮容器 */
	.button-container {
		position: fixed;
		bottom: 0;
		left: 0;
		right: 0;
		height: 120rpx;
		background: white;
		display: flex;
		align-items: center;
		justify-content: space-around;
		border-top: 1rpx solid #eee;
		z-index: 9;

		/* 适配安全区域（iPhone X等） */
		padding-bottom: constant(safe-area-inset-bottom);
		padding-bottom: env(safe-area-inset-bottom);
	}

	/* 单个按钮样式 */
	.bottom-button {
		flex: 1;
		/* 等分宽度 */
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
		height: 100%;
	}

	/* 按钮图标 */
	.button-icon {
		width: 48rpx;
		height: 48rpx;
		margin-bottom: 8rpx;
	}

	/* 按钮文字 */
	.button-text {
		font-size: 24rpx;
		color: #666;
	}

	/* 点击效果 */
	.bottom-button:active {
		opacity: 0.7;
	}



</style>